Skip to content

fix(interpreter): prevent arithmetic overflow panics#443

Merged
chaliy merged 1 commit intomainfrom
claude/fix-405-Y2nIj
Mar 1, 2026
Merged

fix(interpreter): prevent arithmetic overflow panics#443
chaliy merged 1 commit intomainfrom
claude/fix-405-Y2nIj

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Mar 1, 2026

Summary

  • Replace panic-prone arithmetic operators with wrapping variants
  • Clamp exponent to 0..63, shifts to 0..63
  • Use wrapping_div/rem for i64::MIN/-1 edge case
  • Use wrapping_add/sub/mul/neg for overflow safety

Test plan

  • 8 new tests covering exponent, shift, div/mod, add/mul overflow
  • All 1439 existing tests pass
  • clippy clean

Closes #405

…ft, div ops

- Exponentiation: clamp exponent to 0..=63, use wrapping_pow
- Shifts: clamp shift amount to 0..=63, use wrapping_shl/wrapping_shr
- Division/modulo: use wrapping_div/wrapping_rem (prevents i64::MIN / -1 panic)
- Add/sub/mul: use wrapping_add/wrapping_sub/wrapping_mul
- Unary negation: use wrapping_neg

Closes #405
@chaliy chaliy merged commit 004b5d6 into main Mar 1, 2026
17 checks passed
@chaliy chaliy deleted the claude/fix-405-Y2nIj branch March 12, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C-1] Integer overflow/panic in arithmetic exponentiation and shift operators

2 participants